package com.aidisp.model.admin;

import java.util.Date;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;
import org.hibernate.annotations.ForeignKey;

@Entity(name="sys_admin")
@Cache(usage=CacheConcurrencyStrategy.READ_WRITE)
public class User {
	@Id
	@Column(length=16)
	private String loginName;
	@Column(length=32,nullable=false)
	private String password;
	@Column(length=8)
	private String firstName;
	@Column(length=16)
	private String lastName;
	private Date birthday;
	@Column(length=20)
	private String mobile;
	@Column(length=20)
	private String phone;
	@Column(length=50)
	private String email;
	private int loginCount;
	@Column(length=15)
	private String lastLoginIp;
	private long lastLoginTime;
	private long createTime;
	private boolean isAvailable;
	private int passwordErrorCount;
	private boolean locked;
	private long unlockTime;
	private int lockedCount;
	@ManyToOne
	@JoinColumn(name="creator")
	@ForeignKey(name="user_creator_fk")
	private User creatorUser;
	@ManyToMany
	@Cascade(value={CascadeType.SAVE_UPDATE})
	@ForeignKey(name = "user_group_fk", inverseName = "group_user_fk")
	@JoinTable(name = "sys_user_group", joinColumns = { @JoinColumn(name = "userLoginName") }, inverseJoinColumns = { @JoinColumn(name = "groupId") })
	private Set<Group> groups;
	
	public String getLoginName() {
		return loginName;
	}
	public void setLoginName(String loginName) {
		this.loginName = loginName;
	}
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	public String getFirstName() {
		return firstName;
	}
	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}
	public String getLastName() {
		return lastName;
	}
	public void setLastName(String lastName) {
		this.lastName = lastName;
	}
	public Date getBirthday() {
		return birthday;
	}
	public void setBirthday(Date birthday) {
		this.birthday = birthday;
	}
	public String getMobile() {
		return mobile;
	}
	public void setMobile(String mobile) {
		this.mobile = mobile;
	}
	public String getPhone() {
		return phone;
	}
	public void setPhone(String phone) {
		this.phone = phone;
	}
	public String getEmail() {
		return email;
	}
	public void setEmail(String email) {
		this.email = email;
	}
	public int getLoginCount() {
		return loginCount;
	}
	public void setLoginCount(int loginCount) {
		this.loginCount = loginCount;
	}
	public String getLastLoginIp() {
		return lastLoginIp;
	}
	public void setLastLoginIp(String lastLoginIp) {
		this.lastLoginIp = lastLoginIp;
	}
	public long getLastLoginTime() {
		return lastLoginTime;
	}
	public void setLastLoginTime(long lastLoginTime) {
		this.lastLoginTime = lastLoginTime;
	}
	public long getCreateTime() {
		return createTime;
	}
	public void setCreateTime(long createTime) {
		this.createTime = createTime;
	}
	public boolean isAvailable() {
		return isAvailable;
	}
	public void setAvailable(boolean isAvailable) {
		this.isAvailable = isAvailable;
	}
	public int getPasswordErrorCount() {
		return passwordErrorCount;
	}
	public void setPasswordErrorCount(int passwordErrorCount) {
		this.passwordErrorCount = passwordErrorCount;
	}
	public boolean isLocked() {
		return locked;
	}
	public void setLocked(boolean locked) {
		this.locked = locked;
	}
	public long getUnlockTime() {
		return unlockTime;
	}
	public void setUnlockTime(long unlockTime) {
		this.unlockTime = unlockTime;
	}
	public int getLockedCount() {
		return lockedCount;
	}
	public void setLockedCount(int lockedCount) {
		this.lockedCount = lockedCount;
	}
	public User getCreatorUser() {
		return creatorUser;
	}
	public void setCreatorUser(User creatorUser) {
		this.creatorUser = creatorUser;
	}
	public Set<Group> getGroups() {
		return groups;
	}
	public void setGroups(Set<Group> groups) {
		this.groups = groups;
	}
}
